package com.atguigu.jdbc;

import java.sql.*;

public class UpdateStock {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.加载类驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.连接数据库
        String url = "jdbc:mysql://localhost:3306/day04_test01_bookstore";
        Connection conn = DriverManager.getConnection(url, "root", "123456");

        //3.操作数据库
        String sql = "update books set stock=100 where stock<10";
        PreparedStatement pst = conn.prepareStatement(sql);

        int len = pst.executeUpdate();
        System.out.println(len >= 0?"修改成功":"修改失败");
        pst.close();
        conn.close();
    }
}
